/**
 * 公共基础接口封装
 */
import request from '../utils/request'

// 获取角色列表
export const getRoles = () => {
  return request({
    method: 'GET',
    url: '/roles'
  })
}

// 添加角色
export const addRoles = (data) => {
  return request({
    method: 'POST',
    url: '/roles',
    data
  })
}

// 编辑角色
export const editRoles = (roleInfo) => {
  return request({
    method: 'PUT',
    url: `/roles/${roleInfo.id}`,
    data: {
      roleName: roleInfo.roleName,
      roleDesc: roleInfo.roleDesc
    }
  })
}

// 删除角色
export const deleteRoles = (id) => {
  return request({
    method: 'DELETE',
    url: `/roles/${id}`
  })
}

// 获取权限树
export const getRightsTree = () => {
  return request({
    method: 'GET',
    url: '/rights/tree'
  })
}

// 获取权限树
export const setRoleRights = (id, idStr) => {
  return request({
    method: 'POST',
    url: `/roles/${id}/rights`,
    data: {rids: idStr}
  })
}

// 删除角色
export const deleteRightsById = (roleId, rightsId) => {
  return request({
    method: 'DELETE',
    url: `/roles/${roleId}/rights/${rightsId}`
  })
}
